package com.eet.message.config;

import com.eet.message.constants.CommonConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 消息队列配置类
 *
 * @author zheng.zhang
 */
@Configuration
public class RabbitMqConfiguration {

    /**
     * 交换器配置
     *
     * @return 交换机
     */
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange(CommonConstants.FANOUT_EXCHANGE, true, false);
    }

    @Bean
    public Queue emailQueue() {
        return new Queue(CommonConstants.FANOUT_EMAIL_QUEUE, true, false, false);
    }

    @Bean
    public Queue smsQueue() {
        return new Queue(CommonConstants.FANOUT_SMS_QUEUE, true, false, false);
    }

    @Bean
    public Queue weChatQueue() {
        return new Queue(CommonConstants.FANOUT_WECHAT_QUEUE, true, false, false);
    }

    @Bean
    public Binding emailBinding() {
        return BindingBuilder.bind(emailQueue())
                .to(fanoutExchange());
    }

    @Bean
    public Binding smsBinding() {
        return BindingBuilder.bind(smsQueue())
                .to(fanoutExchange());
    }

    @Bean
    public Binding weChatBinding() {
        return BindingBuilder.bind(weChatQueue())
                .to(fanoutExchange());
    }
}
